package com.ruoyi.web.controller.erp;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProgressTemplateNode;
import com.ruoyi.system.service.IProgressTemplateService;
import com.ruoyi.system.mapper.ProgressTemplateNodeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 进度节点Controller
 *-----------这个控制层基本没有用-------------
 * @author ruoyi
 */
@RestController
@RequestMapping("/erp/progress/node")
public class ProgressTemplateNodeController extends BaseController {

    @Autowired
    private ProgressTemplateNodeMapper nodeMapper;

    @Autowired
    private IProgressTemplateService progressTemplateService;

    /**
     * 查询模板节点列表
     */
    @GetMapping("/template/{templateId}")
    public AjaxResult listTemplateNodes(@PathVariable Long templateId) {
        List<ProgressTemplateNode> nodes = nodeMapper.selectNodesByTemplateId(templateId);
        return success(nodes);
    }

//    /**
//     * 查询订单节点列表
//     */
//    @GetMapping("/order/{orderId}")
//    public AjaxResult listOrderNodes(@PathVariable Long orderId) {
//        List<ProgressTemplateNode> nodes = nodeMapper.selectNodesByOrderId(orderId);
//        return success(nodes);
//    }

    /**
     * 获取单个节点信息
     */
    @GetMapping("/{nodeId}")
    public AjaxResult getNode(@PathVariable Long nodeId) {
        return success(nodeMapper.selectNodeById(nodeId));
    }

    /**
     * 新增节点
     */
    @PostMapping
    @Log(title = "进度节点管理", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody ProgressTemplateNode node) {
        return toAjax(nodeMapper.insertNode(node));
    }

    /**
     * 修改节点
     */
    @PutMapping
    @Log(title = "进度节点管理", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody ProgressTemplateNode node) {
        return toAjax(nodeMapper.updateNode(node));
    }

    /**
     * 删除节点
     */
    @DeleteMapping("/{nodeIds}")
    @Log(title = "进度节点管理", businessType = BusinessType.DELETE)
    public AjaxResult remove(@PathVariable Long[] nodeIds) {
        return toAjax(nodeMapper.deleteNodeByIds(nodeIds));
    }

    /**
     * 获取下一个节点
     */
    @GetMapping("/next/{currentNodeId}")
    public AjaxResult getNextNode(@PathVariable Long currentNodeId) {
        return success(nodeMapper.getNextNode(currentNodeId));
    }

    /**
     * 根据模板创建进度节点
     */
//    @PostMapping("/create/{templateId}/{orderId}")
//    @Log(title = "进度节点管理", businessType = BusinessType.INSERT)
//    public AjaxResult createFromTemplate(@PathVariable Long templateId, @PathVariable Long orderId) {
//        List<ProgressTemplateNode> nodes = progressTemplateService.createProgressFromTemplate(templateId, orderId);
//        return success(nodes);
//    }
}
